﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TempinfoDB : BaseDB
    {
        public TempinfoDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TempinfoDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "INSERT INTO tEmpInfo (OrgSid,OrgEmpSid,EmpName,FirstName,MiddleName,LastName,TaxFileNumber,PayStartDate,PayFrequency,NextPayday,NetPayment,Address1,Address2,PaymentDD,PaymentMM,PaymentYY,NextpayDD,NextpayMM,NextpayYY,IsValid) VALUES (", detail.OrgSid, ",'", StringUtils.ToSQL(detail.OrgEmpSid), "','", StringUtils.ToSQL(detail.EmpName), "','", StringUtils.ToSQL(detail.FirstName), "','", StringUtils.ToSQL(detail.MiddleName), "','", StringUtils.ToSQL(detail.LastName), "','", StringUtils.ToSQL(detail.TaxFileNumber), "','", StringUtils.ToSQL(detail.PayStartDate), 
                "','", StringUtils.ToSQL(detail.PayFrequency), "','", StringUtils.ToSQL(detail.NextPayday), "',", detail.NetPayment, ",'", StringUtils.ToSQL(detail.Address1), "','", StringUtils.ToSQL(detail.Address2), "','", StringUtils.ToSQL(detail.PaymentDD), "','", StringUtils.ToSQL(detail.PaymentMM), "','", StringUtils.ToSQL(detail.PaymentYY), 
                "','", StringUtils.ToSQL(detail.NextpayDD), "','", StringUtils.ToSQL(detail.NextpayMM), "','", StringUtils.ToSQL(detail.NextpayYY), "',", detail.IsValid, ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public int AddId(TempinfoDT detail)
        {
            int num = 0;
            int num2 = 0;
            string strSql = string.Concat(new object[] { 
                "INSERT INTO tEmpInfo (OrgSid,OrgEmpSid,EmpName,FirstName,MiddleName,LastName,TaxFileNumber,PayStartDate,PayFrequency,NextPayday,NetPayment,Address1,Address2,PaymentDD,PaymentMM,PaymentYY,NextpayDD,NextpayMM,NextpayYY,IsValid) VALUES (", detail.OrgSid, ",'", StringUtils.ToSQL(detail.OrgEmpSid), "','", StringUtils.ToSQL(detail.EmpName), "','", StringUtils.ToSQL(detail.FirstName), "','", StringUtils.ToSQL(detail.MiddleName), "','", StringUtils.ToSQL(detail.LastName), "','", StringUtils.ToSQL(detail.TaxFileNumber), "','", StringUtils.ToSQL(detail.PayStartDate), 
                "','", StringUtils.ToSQL(detail.PayFrequency), "','", StringUtils.ToSQL(detail.NextPayday), "',", detail.NetPayment, ",'", StringUtils.ToSQL(detail.Address1), "','", StringUtils.ToSQL(detail.Address2), "','", StringUtils.ToSQL(detail.PaymentDD), "','", StringUtils.ToSQL(detail.PaymentMM), "','", StringUtils.ToSQL(detail.PaymentYY), 
                "','", StringUtils.ToSQL(detail.NextpayDD), "','", StringUtils.ToSQL(detail.NextpayMM), "','", StringUtils.ToSQL(detail.NextpayYY), "',", detail.IsValid, ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                    if (num > 0)
                    {
                        strSql = "SELECT @@IDENTITY AS 'Identity'";
                        DataTable table = base.ExecuteForDataTable(strSql);
                        if (table.Rows.Count > 0)
                        {
                            num2 = Convert.ToInt32(table.Rows[0][0].ToString());
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            if (num == 1)
            {
                return num2;
            }
            return 0;
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tEmpInfo where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TempinfoDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "UPDATE tEmpInfo set OrgSid=", detail.OrgSid, ",OrgEmpSid='", StringUtils.ToSQL(detail.OrgEmpSid), "',EmpName='", StringUtils.ToSQL(detail.EmpName), "',FirstName='", StringUtils.ToSQL(detail.FirstName), "',MiddleName='", StringUtils.ToSQL(detail.MiddleName), "',LastName='", StringUtils.ToSQL(detail.LastName), "',TaxFileNumber='", StringUtils.ToSQL(detail.TaxFileNumber), "',PayStartDate='", StringUtils.ToSQL(detail.PayStartDate), 
                "',PayFrequency='", StringUtils.ToSQL(detail.PayFrequency), "',NextPayday='", StringUtils.ToSQL(detail.NextPayday), "',NetPayment=", detail.NetPayment, ",Address1='", StringUtils.ToSQL(detail.Address1), "',Address2='", StringUtils.ToSQL(detail.Address2), "',PaymentDD='", StringUtils.ToSQL(detail.PaymentDD), "',PaymentMM='", StringUtils.ToSQL(detail.PaymentMM), "',PaymentYY='", StringUtils.ToSQL(detail.PaymentYY), 
                "',NextpayDD='", StringUtils.ToSQL(detail.NextpayDD), "',NextpayMM='", StringUtils.ToSQL(detail.NextpayMM), "',NextpayYY='", StringUtils.ToSQL(detail.NextpayYY), "',IsValid=", detail.IsValid, " where (Sid=", detail.Sid, ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TempinfoDT Get(int Sid)
        {
            TempinfoDT odt = new TempinfoDT();
            try
            {
                try
                {
                    string strSql = "select * from tEmpInfo where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        odt.Sid = Convert.ToInt32(row["Sid"]);
                        odt.OrgSid = Convert.ToInt32(row["OrgSid"]);
                        odt.OrgEmpSid = Convert.ToString(row["OrgEmpSid"]);
                        odt.EmpName = Convert.ToString(row["EmpName"]);
                        odt.FirstName = Convert.ToString(row["FirstName"]);
                        odt.MiddleName = Convert.ToString(row["MiddleName"]);
                        odt.LastName = Convert.ToString(row["LastName"]);
                        odt.TaxFileNumber = Convert.ToString(row["TaxFileNumber"]);
                        odt.PayStartDate = Convert.ToString(row["PayStartDate"]);
                        odt.PayFrequency = Convert.ToString(row["PayFrequency"]);
                        odt.NextPayday = Convert.ToString(row["NextPayday"]);
                        odt.NetPayment = Convert.ToDecimal(row["NetPayment"]);
                        odt.Address1 = Convert.ToString(row["Address1"]);
                        odt.Address2 = Convert.ToString(row["Address2"]);
                        odt.PaymentDD = Convert.ToString(row["PaymentDD"]);
                        odt.PaymentMM = Convert.ToString(row["PaymentMM"]);
                        odt.PaymentYY = Convert.ToString(row["PaymentYY"]);
                        odt.NextpayDD = Convert.ToString(row["NextpayDD"]);
                        odt.NextpayMM = Convert.ToString(row["NextpayMM"]);
                        odt.NextpayYY = Convert.ToString(row["NextpayYY"]);
                        odt.IsValid = Convert.ToInt32(row["IsValid"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return odt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tEmpInfo";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

